package com.lagou.testpool;

import com.lagou.Utils.C3P0Utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

public class TestC3P0 {
    //需求 查询姓名为李白的记录
    public static void main(String[] args) throws Exception{
        //1.获取连接
        Connection connection= C3P0Utils.getConnection();

        //2.获取预处理对象
        PreparedStatement preparedStatement=connection.prepareStatement("select * from employee where ename=?");

        //3.设置占位符的值
        preparedStatement.setString(1,"李白");
        ResultSet resultSet=preparedStatement.executeQuery();

        //4.处理结果集
        while(resultSet.next()){
            int eid=resultSet.getInt("eid");
            String ename=resultSet.getString("ename");
            int age=resultSet.getInt("age");
            String sex=resultSet.getString("sex");
            Double salary=resultSet.getDouble("salary");
            Date empdate=resultSet.getDate("empdate");

            System.out.println(eid+","+ename+","+age+","+sex+","+salary+","+empdate);
        }

        //5.释放资源
        C3P0Utils.close(connection,preparedStatement,resultSet);
    }
}
